var a = getApp();

Page({
    data: {
        id: "",
        address: {
            name: "",
            phone: "",
            address: ""
        },
        userId: wx.getStorageSync("userId")
    },
    onLoad: function(e) {
        var t = this;
        if (e.id && e.id.length > 0) {
            t.setData({
                id: e.id
            });
            var d = a.globalData.urlBase + a.globalData.urlDefaultAddress;
            this.getAddressData(d);
        }
    },
    getAddressData: function(e) {
        var t = this;
        wx.request({
            url: e,
            data: {
                userId: t.data.userId,
                addressId: t.data.id
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(e) {
                var d = JSON.parse(e.data);
                0 != d.code && 99 != d.code ? wx.showToast({
                    title: d.msg,
                    icon: "none",
                    duration: 2e3
                }) : (a.globalData.addressId = d.address.id, t.setData({
                    address: d.address
                }));
            }
        });
    },
    updateData: function(a, e) {
        wx.request({
            url: a,
            data: e,
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var e = JSON.parse(a.data);
                0 != e.code ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                }) : wx.navigateBack({
                    url: "../delivAddress/delivAddress"
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    setName: function(a) {
        var e = this, t = e.data.address;
        t.name = a.detail.value, e.setData({
            address: t
        });
    },
    setPhone: function(a) {
        var e = this, t = e.data.address;
        t.phone = a.detail.value, e.setData({
            address: t
        });
    },
    setAddress: function(a) {
        var e = this, t = e.data.address;
        t.address = a.detail.value, e.setData({
            address: t
        });
    },
    sub: function() {
        var e = this, t = e.data.id, d = e.data.address, s = a.globalData.urlBase + a.globalData.urlUpdateAddress, n = d.name, o = d.phone, r = d.address;
        return "" == n ? (wx.showToast({
            title: "请输入用户名",
            icon: "none",
            duration: 1e3
        }), !1) : "" == o ? (wx.showToast({
            title: "手机号不能为空",
            icon: "none",
            duration: 1e3
        }), !1) : "" != o && 11 != o.length ? (wx.showToast({
            title: "手机号长度有误！",
            icon: "none",
            duration: 1500
        }), !1) : "" == r ? (wx.showToast({
            title: "请输入详情地址",
            icon: "none",
            duration: 1e3
        }), !1) : /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/.test(o) ? (t && t.length > 0 || (d.userId = e.data.userId), 
        void e.updateData(s, d)) : (wx.showToast({
            title: "手机号有误！",
            icon: "none",
            duration: 1500
        }), !1);
    }
});